home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / hcastle.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  258 lines

  1. /***************************************************************************
  2.  
  3.     Haunted Castle video emulation
  4.  
  5. ***************************************************************************/
  6.  
  7. #include "driver.h"
  8. #include "vidhrdw/konamiic.h"
  9. #include "vidhrdw/generic.h"
  10.  
  11. static struct osd_bitmap *pf1_bitmap;
  12. static struct osd_bitmap *pf2_bitmap;
  13. static unsigned char *dirty_pf1,*dirty_pf2;
  14. unsigned char *hcastle_pf1_videoram,*hcastle_pf2_videoram;
  15. static int gfx_bank;
  16.  
  17.  
  18.  
  19. void hcastle_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  20. {
  21.     int i,chip,pal,clut;
  22.  
  23.     for (chip = 0;chip < 2;chip++)
  24.     {
  25.         for (pal = 0;pal < 8;pal++)
  26.         {
  27.             clut = (pal & 1) + 2 * chip;
  28.             for (i = 0;i < 256;i++)
  29.             {
  30.                 if ((pal & 1) == 0)    /* sprites */
  31.                 {
  32.                     if (color_prom[256 * clut + i] == 0)
  33.                         *(colortable++) = 0;
  34.                     else
  35.                         *(colortable++) = 16 * pal + color_prom[256 * clut + i];
  36.                 }
  37.                 else
  38.                     *(colortable++) = 16 * pal + color_prom[256 * clut + i];
  39.             }
  40.         }
  41.     }
  42. }
  43.  
  44.  
  45.  
  46. /*****************************************************************************/
  47.  
  48. int hcastle_vh_start(void)
  49. {
  50.      if ((pf1_bitmap = osd_create_bitmap(64*8,32*8)) == 0)
  51.         return 1;
  52.     if ((pf2_bitmap = osd_create_bitmap(64*8,32*8)) == 0)
  53.         return 1;
  54.  
  55.     dirty_pf1=malloc (0x1000);
  56.     dirty_pf2=malloc (0x1000);
  57.     memset(dirty_pf1,1,0x1000);
  58.     memset(dirty_pf2,1,0x1000);
  59.  
  60.     return 0;
  61. }
  62.  
  63. void hcastle_vh_stop(void)
  64. {
  65.     osd_free_bitmap(pf1_bitmap);
  66.     osd_free_bitmap(pf2_bitmap);
  67.     free(dirty_pf1);
  68.     free(dirty_pf2);
  69. }
  70.  
  71.  
  72.  
  73. WRITE_HANDLER( hcastle_pf1_video_w )
  74. {
  75.     hcastle_pf1_videoram[offset]=data;
  76.     dirty_pf1[offset]=1;
  77. }
  78.  
  79. WRITE_HANDLER( hcastle_pf2_video_w )
  80. {
  81.     hcastle_pf2_videoram[offset]=data;
  82.     dirty_pf2[offset]=1;
  83. }
  84.  
  85. WRITE_HANDLER( hcastle_gfxbank_w )
  86. {
  87.     gfx_bank = data;
  88. }
  89.  
  90. READ_HANDLER( hcastle_gfxbank_r )
  91. {
  92.     return gfx_bank;
  93. }
  94.  
  95. WRITE_HANDLER( hcastle_pf1_control_w )
  96. {
  97.     if (offset==3)
  98.     {
  99.         if ((data&0x8)==0)
  100.             buffer_spriteram(spriteram+0x800,0x800);
  101.         else
  102.             buffer_spriteram(spriteram,0x800);
  103.     }
  104.     K007121_ctrl_0_w(offset,data);
  105. }
  106.  
  107. WRITE_HANDLER( hcastle_pf2_control_w )
  108. {
  109.     if (offset==3)
  110.     {
  111.         if ((data&0x8)==0)
  112.             buffer_spriteram_2(spriteram_2+0x800,0x800);
  113.         else
  114.             buffer_spriteram_2(spriteram_2,0x800);
  115.     }
  116.     K007121_ctrl_1_w(offset,data);
  117. }
  118.  
  119. /*****************************************************************************/
  120.  
  121. static void draw_sprites( struct osd_bitmap *bitmap, unsigned char *sbank, int bank )
  122. {
  123.     int bank_base = (bank == 0) ? 0x4000 * (gfx_bank & 1) : 0;
  124.     K007121_sprites_draw(bank,bitmap,sbank,(K007121_ctrlram[bank][6]&0x30)*2,0,bank_base,-1);
  125. }
  126.  
  127. /*****************************************************************************/
  128.  
  129. void hcastle_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  130. {
  131.     int offs,tile,color,mx,my,bank,scrollx,scrolly;
  132.     int pf2_bankbase,pf1_bankbase,attr;
  133.     int bit0,bit1,bit2,bit3;
  134.     static int old_pf1,old_pf2;
  135.  
  136.  
  137.     palette_init_used_colors();
  138.     memset(palette_used_colors,PALETTE_COLOR_USED,128);
  139.     palette_used_colors[0*16] = PALETTE_COLOR_TRANSPARENT;
  140.     palette_used_colors[1*16] = PALETTE_COLOR_TRANSPARENT;
  141.     palette_used_colors[2*16] = PALETTE_COLOR_TRANSPARENT;
  142.     palette_used_colors[3*16] = PALETTE_COLOR_TRANSPARENT;
  143.  
  144.     pf1_bankbase = 0x0000;
  145.     pf2_bankbase = 0x4000 * ((gfx_bank & 2) >> 1);
  146.  
  147.     if (K007121_ctrlram[0][3] & 0x01) pf1_bankbase += 0x2000;
  148.     if (K007121_ctrlram[1][3] & 0x01) pf2_bankbase += 0x2000;
  149.  
  150.     if (palette_recalc() || pf1_bankbase!=old_pf1 || pf2_bankbase!=old_pf2)
  151.     {
  152.         memset(dirty_pf1,1,0x1000);
  153.         memset(dirty_pf2,1,0x1000);
  154.     }
  155.     old_pf1=pf1_bankbase;
  156.     old_pf2=pf2_bankbase;
  157.  
  158.     /* Draw foreground */
  159.     bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
  160.     bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
  161.     bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
  162.     bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
  163.     for (my = 0;my < 32;my++)
  164.     {
  165.         for (mx = 0;mx < 64;mx++)
  166.         {
  167.             if (mx >= 32)
  168.                 offs = 0x800 + my*32 + (mx-32);
  169.             else
  170.                 offs = my*32 + mx;
  171.  
  172.             if (!dirty_pf1[offs] && !dirty_pf1[offs+0x400]) continue;
  173.             dirty_pf1[offs]=dirty_pf1[offs+0x400]=0;
  174.  
  175.             tile = hcastle_pf1_videoram[offs+0x400];
  176.             attr = hcastle_pf1_videoram[offs];
  177.             color = attr & 0x7;
  178.             bank = ((attr & 0x80) >> 7) |
  179.                     ((attr >> (bit0+2)) & 0x02) |
  180.                     ((attr >> (bit1+1)) & 0x04) |
  181.                     ((attr >> (bit2  )) & 0x08) |
  182.                     ((attr >> (bit3-1)) & 0x10);
  183.  
  184.             drawgfx(pf1_bitmap,Machine->gfx[0],
  185.                     tile+bank*0x100+pf1_bankbase,
  186.                     ((K007121_ctrlram[0][6]&0x30)*2+16)+color,
  187.                     0,0,
  188.                     8*mx,8*my,
  189.                     0,TRANSPARENCY_NONE,0);
  190.         }
  191.     }
  192.  
  193.     /* Draw background */
  194.     bit0 = (K007121_ctrlram[1][0x05] >> 0) & 0x03;
  195.     bit1 = (K007121_ctrlram[1][0x05] >> 2) & 0x03;
  196.     bit2 = (K007121_ctrlram[1][0x05] >> 4) & 0x03;
  197.     bit3 = (K007121_ctrlram[1][0x05] >> 6) & 0x03;
  198.     for (my = 0;my < 32;my++)
  199.     {
  200.         for (mx = 0;mx < 64;mx++)
  201.         {
  202.             if (mx >= 32)
  203.                 offs = 0x800 + my*32 + (mx-32);
  204.             else
  205.                 offs = my*32 + mx;
  206.  
  207.             if (!dirty_pf2[offs] && !dirty_pf2[offs+0x400]) continue;
  208.             dirty_pf2[offs]=dirty_pf2[offs+0x400]=0;
  209.  
  210.             tile = hcastle_pf2_videoram[offs+0x400];
  211.             attr = hcastle_pf2_videoram[offs];
  212.             color = attr & 0x7;
  213.             bank = ((attr & 0x80) >> 7) |
  214.                     ((attr >> (bit0+2)) & 0x02) |
  215.                     ((attr >> (bit1+1)) & 0x04) |
  216.                     ((attr >> (bit2  )) & 0x08) |
  217.                     ((attr >> (bit3-1)) & 0x10);
  218.  
  219.             drawgfx(pf2_bitmap,Machine->gfx[1],
  220.                     tile+bank*0x100+pf2_bankbase,
  221.                     ((K007121_ctrlram[1][6]&0x30)*2+16)+color,
  222.                     0,0,
  223.                     8*mx,8*my,
  224.                     0,TRANSPARENCY_NONE,0);
  225.         }
  226.     }
  227.  
  228.  
  229. //    /* Sprite priority */
  230. //    if (K007121_ctrlram[0][3]&0x20)
  231.     if ((gfx_bank & 0x04) == 0)
  232.     {
  233.         scrolly = -K007121_ctrlram[1][2];
  234.         scrollx = -((K007121_ctrlram[1][1]<<8)+K007121_ctrlram[1][0]);
  235.         copyscrollbitmap(bitmap,pf2_bitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  236.  
  237.         draw_sprites( bitmap, buffered_spriteram, 0 );
  238.         draw_sprites( bitmap, buffered_spriteram_2, 1 );
  239.  
  240.         scrolly = -K007121_ctrlram[0][2];
  241.         scrollx = -((K007121_ctrlram[0][1]<<8)+K007121_ctrlram[0][0]);
  242.         copyscrollbitmap(bitmap,pf1_bitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  243.     }
  244.     else
  245.     {
  246.         scrolly = -K007121_ctrlram[1][2];
  247.         scrollx = -((K007121_ctrlram[1][1]<<8)+K007121_ctrlram[1][0]);
  248.         copyscrollbitmap(bitmap,pf2_bitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  249.  
  250.         scrolly = -K007121_ctrlram[0][2];
  251.         scrollx = -((K007121_ctrlram[0][1]<<8)+K007121_ctrlram[0][0]);
  252.         copyscrollbitmap(bitmap,pf1_bitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  253.  
  254.         draw_sprites( bitmap, buffered_spriteram, 0 );
  255.         draw_sprites( bitmap, buffered_spriteram_2, 1 );
  256.     }
  257. }
  258.